ld b,5 ;b=5You can also string them together like this:
ld a,5 ;a=5
cp b ;set flags based on (a-b)
jr z,AequalsB ;if a=b -> a-b=0,therefore
;if the Zero flag is set JUMP to AequalsB
:
.
AequalsB: ;
:
.
ld b,6 ;.You've seen how to test for equality. now forGREATER THAN, and LESS THAN:
ld c,5 ;.
ld a,5 ;Set the init values
cp b ;IF a=b
jr z,AB ;THEN goto AB
cp c ;IF a=c
jr z,AC ;THEN goto AC
jr NONE ;ELSE goto NONE (if it didn'tjump one of the other
; times then it must be an ELSE, NOTE:no conditia
; listed. Just a straight 'jr NONE')
:
.
AB::
.
AC:
:
.
NONE:
ld b,7 ;.back to list of instructions
ld a,3 ;Set up valuescp b ;set flags based on (A-B)
jp p,AGreaterThanB ;IF (a-b) is positivethen a>b
jp m,BGreaterThanA ;IF (a-b) is minus(negative) then b>a
jp AEqualsB ;ELSE a=b
:
:
.